package com.wing.others.service;

import com.alibaba.fastjson.JSON;
import com.wing.auth.service.AuthService;
import com.wing.common.utils.JsonResult;
import com.wing.others.entity.request.OthersCreateRequest;
import com.wing.redis.utils.redis.RedisHelperImpl;
import com.wing.sales.entity.request.SalesCreateRequest;
import com.wing.set.entity.ChanjetSet;
import com.wing.set.service.ChanjetSetService;
import com.wing.util.ConstantsUtil;
import com.wing.util.HttpsUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 *领料出库
 */
@Service
@Slf4j
public class OthersServiceImpl implements com.wing.others.service.OthersService {

    @Resource
    RedisHelperImpl redisHelper;

    @Resource
    AuthService authService;

    @Resource
    ChanjetSetService chanjetSetService;

    @Override
    public JsonResult syncOutOthersDispatch(OthersCreateRequest othersCreateRequest) {
        ChanjetSet chanjetSet = chanjetSetService.getById(1L);

        Map<String, String> headers = new HashMap<>();
        headers.put("appKey", chanjetSet.getAppKey());
        headers.put("appSecret", chanjetSet.getAppSecret());
        if(redisHelper.getValue("chanjetToken") == null){
            authService.getToken();
        }
        headers.put("openToken", redisHelper.getValue("chanjetToken").toString());
        // 创建最外层map，包含dto
        Map<String, Object> root = new HashMap<>();
        othersCreateRequest.setRDRecordDetails(othersCreateRequest.getRes());
        root.put("dto",othersCreateRequest);

        String result = HttpsUtils.httpsPostByJson(ConstantsUtil.CREATE_OTHER_DISPATCH_OPENAPI, headers, JSON.toJSONString(root));

        return JsonResult.success(result);
    }









}
